package com.sunjob.mrologdb.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunjob.common.domain.system.SysBusinessLog;
import com.sunjob.common.result.Result;
import com.sunjob.mrologdb.service.BusinessLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author LongJunJiang
 * @create 2022-08-10-16:15
 */
@Api(value = "业务日志api", tags = "业务日志api")
@RestController
@CrossOrigin
public class BusinessLogController {

    @Autowired
    public BusinessLogService businessLogService;

    /**
     * 查询所有业务日志
     *
     * @return
     */
    @ApiOperation(value = "查询所有业务日志")
    @GetMapping("/queryAllBusinessLog")
    public Result<List<SysBusinessLog>> queryAllBusinessLog() {
        List<SysBusinessLog> sysBusinessLogList = businessLogService.queryAllBusinessLog();
        return Result.ok(sysBusinessLogList, "查询业务成功");
    }

    /**
     * 查询指定业务日志
     *
     * @param businessLogId
     * @return
     */
    @ApiOperation(value = "查询指定日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businessLogId", value = "业务日志编号")
    })
    @GetMapping("/queryBusinessLogById/{businessLogId}")
    public Result<SysBusinessLog> queryBusinessLogById(@PathVariable("businessLogId") Long businessLogId) {
        SysBusinessLog sysBusinessLog = businessLogService.queryBusinessLogById(businessLogId);
        return Result.ok(sysBusinessLog, "查询业务日志成功");
    }

    /**
     * 仅供openfein 远程调用 查询业务日志
     *
     * @param sysBusinessLog
     * @return
     */
    @ApiOperation(value = "条件查询业务日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysBusinessLog", value = "业务日志实体")
    })
    @PostMapping("/queryBusinessLogBy")
    @SaCheckPermission("monitor:businesslog:query")
    Result<List<Map>> querySysBusinessLogBy(@RequestBody SysBusinessLog sysBusinessLog) {
        return Result.ok(businessLogService.querySysBusinessLogBy(sysBusinessLog), "查询业务日志成功");
    }

    /**
     * 查询指定业务日志map
     *
     * @param businessLogId
     * @return
     */
    @GetMapping("/queryBusinessLogMapById/{businessLogId}")
    public Result<Map> queryBusinessLogMapById(@PathVariable("businessLogId") Long businessLogId) {
        Map sysBusinessLog = businessLogService.queryBusinessMapLogById(businessLogId);
        return Result.ok(sysBusinessLog, "查询业务日志成功");
    }
}